﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.ShareData
{
    public class TcmsympDictService : CrudAppService<TcmsympDict, TcmsympDictDto, Guid, TcmsympDictInput, TcmsympDictCreateOrUpdateDto, TcmsympDictCreateOrUpdateDto>
    {
        private IRepository<TcmsympDict, Guid> _TcmsympDictRepository;

        public TcmsympDictService(IRepository<TcmsympDict, Guid> TcmsympDictRepository) : base(TcmsympDictRepository)
        {
            _TcmsympDictRepository = TcmsympDictRepository;
        }

        /// <summary>
        /// 获取临床诊断字典列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<TcmsympDictDto>> GetListAsync(TcmsympDictInput input)
        {
            var iQuery = await _TcmsympDictRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<TcmsympDict>, List<TcmsympDictDto>>(iQuery.ToList());

                return new PagedResultDto<TcmsympDictDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<TcmsympDict>, List<TcmsympDictDto>>(items.ToList());

                return new PagedResultDto<TcmsympDictDto>(totalCount, itemsDto);
            }
        }
    }
}
